package com.h2wallet.newsapi.modular.basic.controller;

import com.h2wallet.newsapi.modular.basic.service.UsersService;
import com.h2wallet.newsapi.modular.basic.vo.EmailAuth;
import com.h2wallet.newsapi.modular.basic.vo.Token;
import com.h2wallet.newsapi.modular.basic.vo.User;
import com.h2wallet.newsapi.modular.basic.vo.UserAuth;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@Api(value= "用户", description="用户相关API")
@RestController
@RequestMapping(value = "/users", produces = MediaType.APPLICATION_JSON_VALUE)
public class UsersController {

    @Resource
    private UsersService usersService;


//    @ApiOperation(value = "用户名注册")
//    @PostMapping
//    public Article post(@RequestBody UserAuth userAuth){
//        return usersService.registerByUsername(userAuth.getUsername(), userAuth.getPassword());
//    }

    @ApiOperation(value = "邮箱注册")
    @PostMapping
    public User post(@RequestBody EmailAuth emailAuth){
        //todo
        return null;
    }

//    @ApiOperation(value = "登录并获取token")
//    @ApiResponses({ @ApiResponse(code = 401, message = "用户名或密码错误") })
//    @PostMapping(value = "/token", consumes = MediaType.APPLICATION_JSON_VALUE)
//    public Token postToken(@RequestBody UserAuth userAuth) {
//        String token = usersService.tokenWithUsername(userAuth.getUsername(), userAuth.getPassword());
//        log.info("用户登录：" + userAuth.getUsername());
//        return new Token(token);
//    }
    @ApiOperation(value = "邮箱登录并获取token")
    @ApiResponses({ @ApiResponse(code = 401, message = "邮箱或或密码错误") })
    @PostMapping(value = "/token")
    public Token postToken(@RequestBody EmailAuth userAuth) {
        return null;
    }


    @ApiOperation(value = "获取用户信息")
    @GetMapping(value = "/{id}")
    public User get(@PathVariable("id") Integer id) {
        return usersService.findOne(id);
    }


}
